package org.dromara.app.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.bean.domain.bo.HisPatientBo;
import org.dromara.bean.domain.vo.HisPatientVo;
import org.dromara.bean.service.IHisPatientService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 就诊卡
 *
 * @author Lion Li
 * @date 2024-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/patient")
public class AHisPatientController extends BaseController {

    private final IHisPatientService hisPatientService;


    /**
     * 查询就诊卡列表
     */
    @GetMapping("/list")
    public TableDataInfo<HisPatientVo> list(HisPatientBo bo, PageQuery pageQuery) {
        return hisPatientService.xcxQueryPageList(bo, pageQuery);
    }


    /**
     * 查询就诊卡详情
     */
    @GetMapping("/{id}")
    public R<HisPatientVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(hisPatientService.queryById(id));
    }


    /**
     * 新增就诊卡
     */
    @Log(title = "就诊卡", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HisPatientBo bo) {
        return toAjax(hisPatientService.insertByBo(bo));
    }

    /**
     * 修改就诊卡
     */
    @Log(title = "就诊卡", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HisPatientBo bo) {
        return toAjax(hisPatientService.updateByBo(bo));
    }

    /**
     * 删除就诊卡
     *
     * @param ids 主键串
     */
    @Log(title = "就诊卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hisPatientService.deleteWithValidByIds(List.of(ids), true));
    }
}
